<template>
    <div class="OpenTabsByData">
        <a-tabs>
            <a-tab-pane :key="item.key" v-for="item of allFormConfig" :tab="item.title">
                <form-solution-show
                    :initConfig="item"
                    :alias="item.alias"
                    :params="item.params"
                    :setInitData="item.setInitData"
                    :read-only="item.readOnly"
                    :parent="item.parent"
                    :close-on-save="item.closeOnSave"
                    :layerid="item.key"
                ></form-solution-show>
            </a-tab-pane>
        </a-tabs>
    </div>
</template>

<script>

import FormSolutionShow from "@/views/modules/form/FormSolutionShow/FormSolutionShow.vue"
import {Util} from "@lowcode/jpaas-base-lib"

export default {
    name: "OpenTabsByData",
    components: {FormSolutionShow},
    props: {
        layerid:{},
        allInitConfig:{
            type: Array,
            default: []
        },
    },
    data(){
        return {
            allFormConfig:[]
        }
    },
    created() {
        debugger
        var self = this
        if (this.allInitConfig.length > 0){
            this.allFormConfig=this.allInitConfig
        }
        // 监听buttonFun发出的关闭按钮信息
        this.$bus.on('saveSuccess',  (conf)=> {
            self.saveSuccess(conf);
        });
        console.log(this.allInitConfig)
    },
    beforeDestroy() {
        //销毁事件
        this.$bus.off("saveSuccess");
    },
    methods:{
        saveSuccess(config){
            debugger
            if (this.formCallBack){
                debugger
            }
            let closeObj = this.allFormConfig.filter(item=> item.key == config.key)
            if (closeObj && closeObj.length>0){
                closeObj = closeObj[0]
                //表单回调方法
                if (closeObj.formCallBack){
                    closeObj.formCallBack("ok",config.formJson.data)
                }
            }
            debugger

            this.allFormConfig = this.allFormConfig.filter(item=> item.key != config.key)
            if (this.allFormConfig.length==0){
                Util.closeWindow(this,"closeTab");
            }
            this.$forceUpdate()
        }
    }
}
</script>

<style scoped>
.OpenTabsByData{
    height: 100%;
}
.OpenTabsByData>>>.ant-tabs-nav{
    padding: 0px 20px;
}
</style>
